<template>
  <div id="target">
    <el-table
      v-if="noResponse"
      v-loading="loading"
      style="width: 100%;height: 419px;margin: 10px auto;z-index: 1">
    </el-table>
    <el-empty v-if="isEmpty" :image-size="200"></el-empty>
    <div class="box" v-if="!isEmpty">
      <div class="cards" v-for="(item, index) in contentData" :key="index">
        <div class="cards-top">
          {{item.blinkContext}}
        </div>
        <div class="cards-bottom">
          <div class="cards-bottom-pubTime"><i class="iconfont icon-shijian cards-bottom-icn"></i>
            {{item.blinkDate | formatDate}}
          </div>
          <div class="cards-bottom-like"><a href="javascript:;"><i class="iconfont icon-xihuan" style="font-size: 20px;"></i></a>
            {{item.blinkLike}}
          </div>
          <div class="cards-bottom-edit">
            <router-link target="_blank" :to="{path:'/publishPage/blink',query:{workId:item.blinkId}}" :title="$t('userAdmin.works.blink.edit')">
              <i class="iconfont icon-bianji"></i>
            </router-link>
          </div>
          <div class="cards-bottom-delete">
            <a href="javascript:;" :title="$t('userAdmin.works.blink.delete')" @click="deleteArticle(item.blinkId)">
              <i class="iconfont icon-shanchu"></i>
            </a>
          </div>
        </div>
      </div>

    </div>
    <el-pagination
      v-if="!isEmpty && !noResponse"
      background
      layout="prev, pager, next"
      :total=pageTotal
      @current-change="handleCurrentChange(currentPage)"
      :current-page.sync = currentPage
      class="page">
    </el-pagination>
  </div>
</template>

<script>
    export default {
        name: "UserAdminMyWorks-blinkCarder",
        data(){
            return{
                loading:"true",
                isEmpty:false,
                noResponse: true,
                baseURL:'http://localhost:8081/userAdmin/blink/',
                baseURL2:'http://localhost:8081/userAdmin/getPages/blink',
                baseURL3:'http://localhost:8081/userAdmin/delete/blink/',
                contentData:'',
                pageTotal:0,
                currentPage:1  // 当前页
            }
        },
        mounted(){
            this.$emit("component","blink")
            this.getCardInfo()
            this.getPages()
        },
        methods:{
            getCardInfo(){
                this.axios.post(this.baseURL+this.currentPage).then(res=>{
                    this.noResponse=false
                    if (res.data != "empty"){
                        this.contentData = res.data
                    }else {
                        this.isEmpty = true
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            getPages(){
                this.axios.post(this.baseURL2).then(res=>{
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            deleteArticle(articleId){
                this.$confirm(this.$t('userAdmin.works.blink.confirm.info'), {
                    confirmButtonText: this.$t('userAdmin.works.blink.confirm.confirm'),
                    cancelButtonText: this.$t('userAdmin.works.blink.confirm.cancel'),
                    showClose: false,
                    type: 'warning'
                }).then(() => {
                    this.axios.post(this.baseURL3+articleId).then(res=>{
                        if (res.data ==true) {
                            this.successOpt(this.$t('userAdmin.works.blink.confirm.successTip'))
                            this.getCardInfo()
                        } else {
                            this.failOpt(this.$t('userAdmin.works.blink.confirm.faiTip'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }).catch(() => {
                    console.log(this.$t('userAdmin.works.blink.confirm.cancelTip'))
                });
            },
            handleCurrentChange(currentPage){
                this.axios.post(this.baseURL+currentPage).then(res=>{
                    this.noResponse=false
                    if (res.data != "empty"){
                        this.contentData = res.data
                        let target = document.getElementById("target").offsetTop
                        window.scrollTo({
                            top:target,
                            behavior: "smooth"
                        });
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .box{
    width: 100%;
    /*width: 800px;*/
    min-height: 115px;
    border-left: rgb(206, 206, 206) solid 2px;
    padding-top: 1px;
    padding-bottom: 10px;
    margin-left: 38px;
    margin-top: 5px;
    letter-spacing: 1px;
  }
  .cards{
    width: 100%;
    /*width: 800px;*/
    min-height: 90px;
    border: solid 1px rgb(224, 224, 224);
    background-image: radial-gradient(circle at 20px, transparent 8px,rgba(255, 255, 255,1) 0px);
    border-radius: 3px;
    margin-top: 10px;
    margin-left: -40px;
    transition: 0.3s;
    position: relative;
  }
  .cards:hover{
    box-shadow: 0 0 5px rgb(206, 206, 206);
    transform:translateY(-1px);
  }
  .cards-top{
    line-height: 100%;
    padding-left: 45px;
    padding-right: 45px;
    padding-top: 20px;
    padding-bottom: 10px;
    color: rgb(77, 77, 77);
    font-size: 16px;
    line-height: 22px;
  }
  .cards-bottom{
    height: 40px;
  }
  .cards-bottom div{
    float: left;
    color: rgb(126, 126, 126);

  }
  .cards-bottom-headPho{
    width: 550px;
  }
  .cards-bottom-headPho div:nth-child(1){
    width: 20px;
    height: 20px;
    margin-top: 8px;
    margin-left: 45px;
  }
  .cards-bottom-headPho div:nth-child(2){
    height: 20px;
    width: 110px;
    margin-left: 5px;
    margin-top: 8px;
    line-height: 20px;
    font-size: 10px;

    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .cards-bottom-pubTime{
    width: 200px;
    line-height: 36px;
    font-size: 11px;
    margin-left: 500px;
  }
  .cards-bottom-like{
    width: 70px;
    line-height: 35px;
    font-size: 11px;
  }
  .icon-xihuan{
    color: rgb(240, 75, 46);
  }
  .cards-bottom-edit, .cards-bottom-delete{
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    margin-top: 4px;
    margin-left: 20px;
  }
  .cards-bottom-edit a i{
    font-size: 17px;
    color: rgb(179, 179, 179);
  }
  .cards-bottom-edit a i:hover{
    color: rgb(0, 167, 0);
  }
  .cards-bottom-delete a i{
    font-size: 17px;
    color: rgb(179, 179, 179);
  }
  .cards-bottom-delete a i:hover{
    color: rgb(226, 17, 17);
  }
  .cards-bottom-icn{
    margin-right: 5px;
  }
  .page{
    margin: 10px auto;
    margin-left: -10px;
  }
</style>
